<?php
/**
 * WB_CacheAPC class
 * 
 * @author Jean-Lou Dupont
 * @version @@package-version@@
 * @id $Id: CacheAPC.php 94 2008-03-06 20:13:11Z jldupont $
 */

// WB_CacheClass and WB_Singleton_IF must anyhow
// have been required' through WB_CacheManager
 //{{include
 
 //include}}
 
 class WB_CacheAPC
 	extends WB_CacheClass
	implements WB_Singleton_IF
 {
 	/**
 	 * Constructor
 	 */
	public function __construct( $params = null )
	{
		parent::__construct( $params );
	}
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// WB_BaseClass
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
	/**
	 * @see WB_BaseClass::getClassPath
	 */
	public function getClassPath()
	{
		return 'web-bloks/CachesMemory';
	}
	/**
	 * @see WB_BaseClass::getClassVersion
	 * @return 
	 */
	public function getClassVersion()
	{
		return '$Id: CacheAPC.php 94 2008-03-06 20:13:11Z jldupont $';
	}
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// WB_Singleton_IF Interface
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%				
	/**
	 * @private
	 */
	static $instance = null;

	/**
	 * @see WB_Singleton_IF
	 */
	public static function getSingleton( $params = null )	
	{ 
		/**
		 * @see WB_BaseClass::_handleSingleton
		 */
		return self::_handleSingleton( self::$instance, 'WB_CacheAPC', $params );
	}
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// WB_CacheClass Interface
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
	
	public function isFake()
	{
		return false;
	}				
				
	public function getInfo()
	{
		return apc_cache_info();
	}
	
	public static function checkPresence()
	{
		return function_exists( 'apc_fetch' );
	}

	public function clearCache()
	{
		return apc_clear_cache();
	}

	function get($key) 
	{
		$val = apc_fetch($key);
		if ( is_string( $val ) ) 
			$val = unserialize( $val );
		else
			$val = false;

		return $val;
	}
	
	function set($key, $value, $exptime=0) 
	{
		return apc_store($key, serialize($value), $exptime);
	}
	
	function delete($key, $time=0) 
	{
		return apc_delete($key);
	}
}// END APC

// registers this shared memory cache
WB_CacheManager::register( 'WB_CacheAPC' );